$(function () {
    //新增品牌
    $("[name='btn_save_new_brand']").click(function () {
        var form = window.form_new_brand;
        var name = form.name.value;
        var state = form.state.value;

        var brand = {name: name, state: state};

        $.postJsonBody("/brand", brand, function (re) {
            // tipper.success("已保存，请刷新页面");
            // $("#md_new_brand").modal("hide");
        	window.location.href=window.location.href; 
        	window.location.reload; 
        })
    });


    //编辑品牌
    $("[name='btn_save_edit_brand']").click(function () {
        var form = window.form_edit_brand;
        var id = form.id.value;
        var name = form.name.value;
        var state = form.state.value;

        var brand = {id: id, name: name, state: state};
        $.putJsonBody("/brand/" + id, brand, function (re) {
            // tipper.success("已更新，请刷新页面");
            // $("#md_edit_brand").modal("hide");
        	window.location.href=window.location.href; 
        	window.location.reload; 
        })
    });

    //删除品牌
    $("[name='btn_delete_brand']").click(function () {
        var brandId = $(this).data("brand-id");
        bootbox.bconfirm("确定要删除这个品牌吗？", function (re) {
            if (re) {
                $.delete("/brand/" + brandId, function (re) {
                    if (re.data) {
                        // tipper.success("删除成功，请刷新页面");
                    	window.location.href=window.location.href; 
                    	window.location.reload; 
                    } else {
                        tipper.danger("删除失败，请重试");
                    }
                });
            }
        });
    });


    // 任务详情
    $('#md_edit_brand').on('show.bs.modal', function (event) {
        var _e = $(event.relatedTarget);
        var id = _e.data("brand-id");
        var modal = $(this);
        var form = window.form_edit_brand;
        $.get("/brand/" + id, function (re) {
            var brand = re.data;
            form.id.value = brand.id;
            form.name.value = brand.name;
            $(form.state).val(brand.state);
        });
    });
});

